{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "# Deep Learning with PyTorch: A 60 Minute Blitz\n",
    "## Neural Networks"
   ],
   "id": "55dc86e61ebf2fc8"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:29:07.267439Z",
     "start_time": "2024-10-11T13:29:05.918278Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "import torch.nn.functional as F\n",
    "\n",
    "\n",
    "class Net(nn.Module):\n",
    "\n",
    "    def __init__(self):\n",
    "        super(Net, self).__init__()\n",
    "        # 1 input image channel, 6 output channels, 5x5 square convolution\n",
    "        # kernel\n",
    "        self.conv1 = nn.Conv2d(1, 6, 5)\n",
    "        self.conv2 = nn.Conv2d(6, 16, 5)\n",
    "        # an affine operation: y = Wx + b\n",
    "        self.fc1 = nn.Linear(16 * 5 * 5, 120)  # 5*5 from image dimension\n",
    "        self.fc2 = nn.Linear(120, 84)\n",
    "        self.fc3 = nn.Linear(84, 10)\n",
    "\n",
    "    def forward(self, input):\n",
    "        # Convolution layer C1: 1 input image channel, 6 output channels,\n",
    "        # 5x5 square convolution, it uses RELU activation function, and\n",
    "        # outputs a Tensor with size (N, 6, 28, 28), where N is the size of the batch\n",
    "        c1 = F.relu(self.conv1(input))\n",
    "        # Subsampling layer S2: 2x2 grid, purely functional,\n",
    "        # this layer does not have any parameter, and outputs a (N, 6, 14, 14) Tensor\n",
    "        s2 = F.max_pool2d(c1, (2, 2))\n",
    "        # Convolution layer C3: 6 input channels, 16 output channels,\n",
    "        # 5x5 square convolution, it uses RELU activation function, and\n",
    "        # outputs a (N, 16, 10, 10) Tensor\n",
    "        c3 = F.relu(self.conv2(s2))\n",
    "        # Subsampling layer S4: 2x2 grid, purely functional,\n",
    "        # this layer does not have any parameter, and outputs a (N, 16, 5, 5) Tensor\n",
    "        s4 = F.max_pool2d(c3, 2)\n",
    "        # Flatten operation: purely functional, outputs a (N, 400) Tensor\n",
    "        s4 = torch.flatten(s4, 1)\n",
    "        # Fully connected layer F5: (N, 400) Tensor input,\n",
    "        # and outputs a (N, 120) Tensor, it uses RELU activation function\n",
    "        f5 = F.relu(self.fc1(s4))\n",
    "        # Fully connected layer F6: (N, 120) Tensor input,\n",
    "        # and outputs a (N, 84) Tensor, it uses RELU activation function\n",
    "        f6 = F.relu(self.fc2(f5))\n",
    "        # Gaussian layer OUTPUT: (N, 84) Tensor input, and\n",
    "        # outputs a (N, 10) Tensor\n",
    "        output = self.fc3(f6)\n",
    "        return output\n",
    "\n",
    "\n",
    "net = Net()\n",
    "print(net)"
   ],
   "id": "340a179608047c1a",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Net(\n",
      "  (conv1): Conv2d(1, 6, kernel_size=(5, 5), stride=(1, 1))\n",
      "  (conv2): Conv2d(6, 16, kernel_size=(5, 5), stride=(1, 1))\n",
      "  (fc1): Linear(in_features=400, out_features=120, bias=True)\n",
      "  (fc2): Linear(in_features=120, out_features=84, bias=True)\n",
      "  (fc3): Linear(in_features=84, out_features=10, bias=True)\n",
      ")\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:29:54.610939Z",
     "start_time": "2024-10-11T13:29:54.607447Z"
    }
   },
   "cell_type": "code",
   "source": [
    "params = list(net.parameters())\n",
    "print(len(params))\n",
    "print(params[0].size())  # conv1's .weight"
   ],
   "id": "56301ebd668dd5dd",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "torch.Size([6, 1, 5, 5])\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:30:03.653541Z",
     "start_time": "2024-10-11T13:30:03.383510Z"
    }
   },
   "cell_type": "code",
   "source": [
    "input = torch.randn(1, 1, 32, 32)\n",
    "out = net(input)\n",
    "print(out)"
   ],
   "id": "6767ae6cd11abacd",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[-0.1257,  0.0583,  0.0794,  0.0493, -0.0161,  0.0475,  0.0711, -0.0458,\n",
      "         -0.1462,  0.0300]], grad_fn=<AddmmBackward0>)\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:30:14.441384Z",
     "start_time": "2024-10-11T13:30:13.899482Z"
    }
   },
   "cell_type": "code",
   "source": [
    "net.zero_grad()\n",
    "out.backward(torch.randn(1, 10))"
   ],
   "id": "be7755ec6f990fbb",
   "outputs": [],
   "execution_count": 4
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "> torch.nn only supports mini-batches. The entire torch.nn package only supports inputs that are a mini-batch of samples, and not a single sample.\n",
    "For example, nn.Conv2d will take in a 4D Tensor of nSamples x nChannels x Height x Width.\n",
    "If you have a single sample, just use input.unsqueeze(0) to add a fake batch dimension."
   ],
   "id": "34db4bc27ddddddf"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:31:54.231638Z",
     "start_time": "2024-10-11T13:31:54.200177Z"
    }
   },
   "cell_type": "code",
   "source": [
    "output = net(input)\n",
    "target = torch.randn(10)  # a dummy target, for example\n",
    "target = target.view(1, -1)  # make it the same shape as output\n",
    "criterion = nn.MSELoss()\n",
    "\n",
    "loss = criterion(output, target)\n",
    "print(loss)"
   ],
   "id": "82b827fc033d1f54",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor(1.8669, grad_fn=<MseLossBackward0>)\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:32:19.133454Z",
     "start_time": "2024-10-11T13:32:19.113446Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print(loss.grad_fn)  # MSELoss\n",
    "print(loss.grad_fn.next_functions[0][0])  # Linear\n",
    "print(loss.grad_fn.next_functions[0][0].next_functions[0][0])  # ReLU"
   ],
   "id": "f2f752f7ce02db75",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<MseLossBackward0 object at 0x0000012B49946560>\n",
      "<AddmmBackward0 object at 0x0000012B4A274A90>\n",
      "<AccumulateGrad object at 0x0000012B49DBD000>\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:32:51.177526Z",
     "start_time": "2024-10-11T13:32:51.155132Z"
    }
   },
   "cell_type": "code",
   "source": [
    "net.zero_grad()     # zeroes the gradient buffers of all parameters\n",
    "\n",
    "print('conv1.bias.grad before backward')\n",
    "print(net.conv1.bias.grad)\n",
    "\n",
    "loss.backward()\n",
    "\n",
    "print('conv1.bias.grad after backward')\n",
    "print(net.conv1.bias.grad)"
   ],
   "id": "dd50926c41e27a65",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "conv1.bias.grad before backward\n",
      "None\n",
      "conv1.bias.grad after backward\n",
      "tensor([ 0.0328, -0.0143, -0.0186,  0.0113,  0.0035,  0.0177])\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:33:38.375624Z",
     "start_time": "2024-10-11T13:33:37.222415Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import torch.optim as optim\n",
    "\n",
    "# create your optimizer\n",
    "optimizer = optim.SGD(net.parameters(), lr=0.01)\n",
    "\n",
    "# in your training loop:\n",
    "optimizer.zero_grad()   # zero the gradient buffers\n",
    "output = net(input)\n",
    "loss = criterion(output, target)\n",
    "loss.backward()\n",
    "optimizer.step()    # Does the update"
   ],
   "id": "e91a82d275aea389",
   "outputs": [],
   "execution_count": 8
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## Training a Classifier",
   "id": "2adae6ed926b954f"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:38:54.784336Z",
     "start_time": "2024-10-11T13:37:54.668745Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import torch\n",
    "import torchvision\n",
    "import torchvision.transforms as transforms\n",
    "\n",
    "transform = transforms.Compose(\n",
    "    [transforms.ToTensor(),\n",
    "     transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])\n",
    "\n",
    "batch_size = 4\n",
    "\n",
    "trainset = torchvision.datasets.CIFAR10(root='./data', train=True,\n",
    "                                        download=True, transform=transform)\n",
    "trainloader = torch.utils.data.DataLoader(trainset, batch_size=batch_size,\n",
    "                                          shuffle=True, num_workers=2)\n",
    "\n",
    "testset = torchvision.datasets.CIFAR10(root='./data', train=False,\n",
    "                                       download=True, transform=transform)\n",
    "testloader = torch.utils.data.DataLoader(testset, batch_size=batch_size,\n",
    "                                         shuffle=False, num_workers=2)\n",
    "\n",
    "classes = ('plane', 'car', 'bird', 'cat',\n",
    "           'deer', 'dog', 'frog', 'horse', 'ship', 'truck')"
   ],
   "id": "4de9ffe9a45e71c5",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloading https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz to ./data\\cifar-10-python.tar.gz\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 170498071/170498071 [00:55<00:00, 3061993.48it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracting ./data\\cifar-10-python.tar.gz to ./data\n",
      "Files already downloaded and verified\n"
     ]
    }
   ],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:39:30.363122Z",
     "start_time": "2024-10-11T13:39:23.133785Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "# functions to show an image\n",
    "\n",
    "\n",
    "def imshow(img):\n",
    "    img = img / 2 + 0.5     # unnormalize\n",
    "    npimg = img.numpy()\n",
    "    plt.imshow(np.transpose(npimg, (1, 2, 0)))\n",
    "    plt.show()\n",
    "\n",
    "\n",
    "# get some random training images\n",
    "dataiter = iter(trainloader)\n",
    "images, labels = next(dataiter)\n",
    "\n",
    "# show images\n",
    "imshow(torchvision.utils.make_grid(images))\n",
    "# print labels\n",
    "print(' '.join(f'{classes[labels[j]]:5s}' for j in range(batch_size)))"
   ],
   "id": "dc7b93622bf33080",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ],
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAh8AAACwCAYAAACviAzDAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABQQElEQVR4nO29eZAd5X33++vTZ1/mzL5pZjSjDQFCIAQmCGyEbZTCDo5f8ibGxDZO/nhNMA6y7g2LyS0rLixRrvdikluBxL4uoMrhxdevwXZcDkHYIMDCgIUEQgItaKQZafblLHP20/3cPwjntwwzaMToaJnfp0pV3fPr6X766aefaT3f32IZYwwoiqIoiqJUCc/pboCiKIqiKAsL/fhQFEVRFKWq6MeHoiiKoihVRT8+FEVRFEWpKvrxoSiKoihKVdGPD0VRFEVRqop+fCiKoiiKUlX040NRFEVRlKqiHx+KoiiKolQV/fhQFEVRFKWqnLKPj4ceegh6enogGAzC2rVr4cUXXzxVl1IURVEU5SzCeypO+pOf/AQ2btwIDz30EFx11VXwr//6r3D99dfDvn37oKura9bfdV0XBgYGIBaLgWVZp6J5iqIoiqLMM8YYSKfT0N7eDh7P7Gsb1qkoLHfFFVfApZdeCg8//HDlZ+effz58/vOfh61bt876u8eOHYPOzs75bpKiKIqiKFWgv78fOjo6Zj1m3lc+isUi7Ny5E+6++2728w0bNsCOHTumHV8oFKBQKFT23/8W+uY3vwmBQGC+m6coiqIoyimgUCjA97//fY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IRc+TIkdPdtKryN3/zNyYej5vnn3/eDA4OVv5ls9nKMffff7+Jx+PmySefNHv27DFf/OIXz9lQwBOBRrsYs7D759VXXzVer9d897vfNQcPHjT/9m//ZsLhsPnxj39cOWYh988tt9xiFi1aVAm1ffLJJ01jY6O58847K8cspP5Jp9Nm165dZteuXQYAzAMPPGB27dpVidY4kb649dZbTUdHh3n22WfN66+/bj75yU+eM6Gks/VPqVQyn/vc50xHR4fZvXs3m68LhULlHOdy/8yVM/Ljwxhj/vmf/9ksXrzY+P1+c+mll1bCSxcSAPCB/x555JHKMa7rmm9/+9umtbXVBAIB84lPfMLs2bPn9DX6NCM/PhZ6//z7v/+7WbVqlQkEAmblypXmBz/4AbMv5P5JpVLmjjvuMF1dXSYYDJolS5aYe++9l/2xWEj989xzz33gfHPLLbcYY06sL3K5nLn99ttNfX29CYVC5k/+5E9MX1/fabib+We2/unt7Z1xvn7uuecq5ziX+2euWMYYU711FkVRFEVRFjpnnM+HoiiKoijnNvrxoSiKoihKVdGPD0VRFEVRqop+fCiKoiiKUlX040NRFEVRlKqiHx+KoiiKolQV/fhQFEVRFKWq6MeHoiiKoihVRT8+FEVRFEWpKvrxoSiKoihKVdGPD0VRFEVRqsr/Dx7sll61YXs6AAAAAElFTkSuQmCC"
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "frog  bird  truck car  \n"
     ]
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:42:34.128524Z",
     "start_time": "2024-10-11T13:41:05.697537Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import torch.nn as nn\n",
    "import torch.nn.functional as F\n",
    "\n",
    "\n",
    "class Net(nn.Module):\n",
    "    def __init__(self):\n",
    "        super().__init__()\n",
    "        self.conv1 = nn.Conv2d(3, 6, 5)\n",
    "        self.pool = nn.MaxPool2d(2, 2)\n",
    "        self.conv2 = nn.Conv2d(6, 16, 5)\n",
    "        self.fc1 = nn.Linear(16 * 5 * 5, 120)\n",
    "        self.fc2 = nn.Linear(120, 84)\n",
    "        self.fc3 = nn.Linear(84, 10)\n",
    "\n",
    "    def forward(self, x):\n",
    "        x = self.pool(F.relu(self.conv1(x)))\n",
    "        x = self.pool(F.relu(self.conv2(x)))\n",
    "        x = torch.flatten(x, 1) # flatten all dimensions except batch\n",
    "        x = F.relu(self.fc1(x))\n",
    "        x = F.relu(self.fc2(x))\n",
    "        x = self.fc3(x)\n",
    "        return x\n",
    "\n",
    "\n",
    "net = Net()\n",
    "\n",
    "import torch.optim as optim\n",
    "\n",
    "criterion = nn.CrossEntropyLoss()\n",
    "optimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9)\n",
    "\n",
    "for epoch in range(2):  # loop over the dataset multiple times\n",
    "\n",
    "    running_loss = 0.0\n",
    "    for i, data in enumerate(trainloader, 0):\n",
    "        # get the inputs; data is a list of [inputs, labels]\n",
    "        inputs, labels = data\n",
    "\n",
    "        # zero the parameter gradients\n",
    "        optimizer.zero_grad()\n",
    "\n",
    "        # forward + backward + optimize\n",
    "        outputs = net(inputs)\n",
    "        loss = criterion(outputs, labels)\n",
    "        loss.backward()\n",
    "        optimizer.step()\n",
    "\n",
    "        # print statistics\n",
    "        running_loss += loss.item()\n",
    "        if i % 2000 == 1999:    # print every 2000 mini-batches\n",
    "            print(f'[{epoch + 1}, {i + 1:5d}] loss: {running_loss / 2000:.3f}')\n",
    "            running_loss = 0.0\n",
    "\n",
    "print('Finished Training')"
   ],
   "id": "3a14b828d58a11a4",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1,  2000] loss: 2.203\n",
      "[1,  4000] loss: 1.872\n",
      "[1,  6000] loss: 1.682\n",
      "[1,  8000] loss: 1.601\n",
      "[1, 10000] loss: 1.525\n",
      "[1, 12000] loss: 1.463\n",
      "[2,  2000] loss: 1.405\n",
      "[2,  4000] loss: 1.381\n",
      "[2,  6000] loss: 1.356\n",
      "[2,  8000] loss: 1.320\n",
      "[2, 10000] loss: 1.329\n",
      "[2, 12000] loss: 1.284\n",
      "Finished Training\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:42:39.175813Z",
     "start_time": "2024-10-11T13:42:39.170487Z"
    }
   },
   "cell_type": "code",
   "source": [
    "PATH = './model/cifar_net.pth'\n",
    "torch.save(net.state_dict(), PATH)"
   ],
   "id": "f8abc6fb94d337f4",
   "outputs": [],
   "execution_count": 12
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:42:53.893995Z",
     "start_time": "2024-10-11T13:42:47.224655Z"
    }
   },
   "cell_type": "code",
   "source": [
    "dataiter = iter(testloader)\n",
    "images, labels = next(dataiter)\n",
    "\n",
    "# print images\n",
    "imshow(torchvision.utils.make_grid(images))\n",
    "print('GroundTruth: ', ' '.join(f'{classes[labels[j]]:5s}' for j in range(4)))"
   ],
   "id": "1978fa85dc89a53",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ],
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAh8AAACwCAYAAACviAzDAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABOiElEQVR4nO29eZBd1XXvv85w57HnQd2SWkhCAolJEnpgHsgDijHBochgm9jgpH5VJlgOsqrCYFJlxYUlnv8gJFWBxC4HeD+HwskPPMRxKITBAp6MAQ0gJDSh1tytVg+3b/cdz7B/f/C4e6111ZduaF0NvT5Vqjq79+lz9tl7n91H+7sGQymlQBAEQRAEoU6YZ7sBgiAIgiDMLOTjQxAEQRCEuiIfH4IgCIIg1BX5+BAEQRAEoa7Ix4cgCIIgCHVFPj4EQRAEQagr8vEhCIIgCEJdkY8PQRAEQRDqinx8C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574oknKuf4vq+++93vqvb2dhUKhdT111+vdu7cefYafZbhHx8zvX/+8z//Uy1ZskSFQiG1aNEi9cMf/pDUz+T+yWaz6p577lGzZ89W4XBYzZs3Tz344IPkj8VM6p+XX375tOvNnXfeqZSaXF8UCgW1Zs0a1djYqCKRiPrDP/xDdeTIkbPwNNNPrf7p7e2dcL1++eWXK9e4kPtnqhhKKVW/fRZBEARBEGY655zNhyAIgiAIFzby8SEIgiAIQl2Rjw9BEARBEOqKfHwIgiAIglBX5ONDEARBEIS6Ih8fgiAIgiDUFfn4EARBEAShrsjHhyAIgiAIdUU+PgRBEARBqCvy8SEIgiAIQl2Rjw9BEARBEOrK/w988m9fAJGeEQAAAABJRU5ErkJggg=="
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GroundTruth:  cat   ship  ship  plane\n"
     ]
    }
   ],
   "execution_count": 13
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:43:31.508694Z",
     "start_time": "2024-10-11T13:43:31.498542Z"
    }
   },
   "cell_type": "code",
   "source": [
    "net = Net()\n",
    "net.load_state_dict(torch.load(PATH, weights_only=True))"
   ],
   "id": "bc4947da85ff51a5",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<All keys matched successfully>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 14
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:44:15.640861Z",
     "start_time": "2024-10-11T13:44:15.607462Z"
    }
   },
   "cell_type": "code",
   "source": [
    "outputs = net(images)\n",
    "\n",
    "_, predicted = torch.max(outputs, 1)\n",
    "\n",
    "print('Predicted: ', ' '.join(f'{classes[predicted[j]]:5s}'\n",
    "                              for j in range(4)))"
   ],
   "id": "c709e93c8a3c3563",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Predicted:  cat   ship  car   plane\n"
     ]
    }
   ],
   "execution_count": 15
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:45:00.816942Z",
     "start_time": "2024-10-11T13:44:51.859197Z"
    }
   },
   "cell_type": "code",
   "source": [
    "correct = 0\n",
    "total = 0\n",
    "# since we're not training, we don't need to calculate the gradients for our outputs\n",
    "with torch.no_grad():\n",
    "    for data in testloader:\n",
    "        images, labels = data\n",
    "        # calculate outputs by running images through the network\n",
    "        outputs = net(images)\n",
    "        # the class with the highest energy is what we choose as prediction\n",
    "        _, predicted = torch.max(outputs.data, 1)\n",
    "        total += labels.size(0)\n",
    "        correct += (predicted == labels).sum().item()\n",
    "\n",
    "print(f'Accuracy of the network on the 10000 test images: {100 * correct // total} %')"
   ],
   "id": "76425f4d156cc241",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Accuracy of the network on the 10000 test images: 55 %\n"
     ]
    }
   ],
   "execution_count": 16
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T13:46:35.373063Z",
     "start_time": "2024-10-11T13:46:26.243965Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# prepare to count predictions for each class\n",
    "correct_pred = {classname: 0 for classname in classes}\n",
    "total_pred = {classname: 0 for classname in classes}\n",
    "\n",
    "# again no gradients needed\n",
    "with torch.no_grad():\n",
    "    for data in testloader:\n",
    "        images, labels = data\n",
    "        outputs = net(images)\n",
    "        _, predictions = torch.max(outputs, 1)\n",
    "        # collect the correct predictions for each class\n",
    "        for label, prediction in zip(labels, predictions):\n",
    "            if label == prediction:\n",
    "                correct_pred[classes[label]] += 1\n",
    "            total_pred[classes[label]] += 1\n",
    "\n",
    "\n",
    "# print accuracy for each class\n",
    "for classname, correct_count in correct_pred.items():\n",
    "    accuracy = 100 * float(correct_count) / total_pred[classname]\n",
    "    print(f'Accuracy for class: {classname:5s} is {accuracy:.1f} %')"
   ],
   "id": "58d69b630d80925c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Accuracy for class: plane is 58.1 %\n",
      "Accuracy for class: car   is 53.1 %\n",
      "Accuracy for class: bird  is 37.3 %\n",
      "Accuracy for class: cat   is 43.8 %\n",
      "Accuracy for class: deer  is 48.2 %\n",
      "Accuracy for class: dog   is 42.5 %\n",
      "Accuracy for class: frog  is 65.0 %\n",
      "Accuracy for class: horse is 60.6 %\n",
      "Accuracy for class: ship  is 72.2 %\n",
      "Accuracy for class: truck is 70.7 %\n"
     ]
    }
   ],
   "execution_count": 17
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')\n",
    "\n",
    "# Assuming that we are on a CUDA machine, this should print a CUDA device:\n",
    "\n",
    "print(device)\n",
    "\n",
    "net.to(device)\n",
    "\n",
    "inputs, labels = data[0].to(device), data[1].to(device)\n",
    "\n"
   ],
   "id": "ee0234080628b22a"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# Learning PyTorch with Examples",
   "id": "ddac8df65a500f8c"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T14:23:12.364222Z",
     "start_time": "2024-10-11T14:23:11.615048Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "import numpy as np\n",
    "import math\n",
    "\n",
    "# Create random input and output data\n",
    "x = np.linspace(-math.pi, math.pi, 2000)\n",
    "y = np.sin(x)\n",
    "\n",
    "# Randomly initialize weights\n",
    "a = np.random.randn()\n",
    "b = np.random.randn()\n",
    "c = np.random.randn()\n",
    "d = np.random.randn()\n",
    "\n",
    "learning_rate = 1e-6\n",
    "for t in range(2000):\n",
    "    # Forward pass: compute predicted y\n",
    "    # y = a + b x + c x^2 + d x^3\n",
    "    y_pred = a + b * x + c * x ** 2 + d * x ** 3\n",
    "\n",
    "    # Compute and print loss\n",
    "    loss = np.square(y_pred - y).sum()\n",
    "    if t % 100 == 99:\n",
    "        print(t, loss)\n",
    "\n",
    "    # Backprop to compute gradients of a, b, c, d with respect to loss\n",
    "    grad_y_pred = 2.0 * (y_pred - y)\n",
    "    grad_a = grad_y_pred.sum()\n",
    "    grad_b = (grad_y_pred * x).sum()\n",
    "    grad_c = (grad_y_pred * x ** 2).sum()\n",
    "    grad_d = (grad_y_pred * x ** 3).sum()\n",
    "\n",
    "    # Update weights\n",
    "    a -= learning_rate * grad_a\n",
    "    b -= learning_rate * grad_b\n",
    "    c -= learning_rate * grad_c\n",
    "    d -= learning_rate * grad_d\n",
    "\n",
    "print(f'Result: y = {a} + {b} x + {c} x^2 + {d} x^3')"
   ],
   "id": "d449fe9c2ec9f6fa",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 3711.2369815341003\n",
      "199 2465.9560157832702\n",
      "299 1639.908859183724\n",
      "399 1091.8408193115818\n",
      "499 728.1256798371214\n",
      "599 486.6954630126341\n",
      "699 326.3961646306539\n",
      "799 219.93575928660835\n",
      "899 149.21153384747637\n",
      "999 102.21353938877715\n",
      "1099 70.97222413237533\n",
      "1199 50.19792699624959\n",
      "1299 36.378851780808304\n",
      "1399 27.18291068503236\n",
      "1499 21.060996062493235\n",
      "1599 16.983796631676643\n",
      "1699 14.267167652585055\n",
      "1799 12.456232693392977\n",
      "1899 11.248445696456672\n",
      "1999 10.442503315086377\n",
      "Result: y = 0.017366853738026395 + 0.820942972428576 x + -0.002996071255503142 x^2 + -0.08823845367191815 x^3\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T14:26:44.826794Z",
     "start_time": "2024-10-11T14:26:41.999542Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "\n",
    "import torch\n",
    "import math\n",
    "\n",
    "\n",
    "dtype = torch.float\n",
    "device = torch.device(\"cpu\")\n",
    "# device = torch.device(\"cuda:0\") # Uncomment this to run on GPU\n",
    "\n",
    "# Create random input and output data\n",
    "x = torch.linspace(-math.pi, math.pi, 2000, device=device, dtype=dtype)\n",
    "y = torch.sin(x)\n",
    "\n",
    "# Randomly initialize weights\n",
    "a = torch.randn((), device=device, dtype=dtype)\n",
    "b = torch.randn((), device=device, dtype=dtype)\n",
    "c = torch.randn((), device=device, dtype=dtype)\n",
    "d = torch.randn((), device=device, dtype=dtype)\n",
    "\n",
    "learning_rate = 1e-6\n",
    "for t in range(2000):\n",
    "    # Forward pass: compute predicted y\n",
    "    y_pred = a + b * x + c * x ** 2 + d * x ** 3\n",
    "\n",
    "    # Compute and print loss\n",
    "    loss = (y_pred - y).pow(2).sum().item()\n",
    "    if t % 100 == 99:\n",
    "        print(t, loss)\n",
    "\n",
    "    # Backprop to compute gradients of a, b, c, d with respect to loss\n",
    "    grad_y_pred = 2.0 * (y_pred - y)\n",
    "    grad_a = grad_y_pred.sum()\n",
    "    grad_b = (grad_y_pred * x).sum()\n",
    "    grad_c = (grad_y_pred * x ** 2).sum()\n",
    "    grad_d = (grad_y_pred * x ** 3).sum()\n",
    "\n",
    "    # Update weights using gradient descent\n",
    "    a -= learning_rate * grad_a\n",
    "    b -= learning_rate * grad_b\n",
    "    c -= learning_rate * grad_c\n",
    "    d -= learning_rate * grad_d\n",
    "\n",
    "\n",
    "print(f'Result: y = {a.item()} + {b.item()} x + {c.item()} x^2 + {d.item()} x^3')"
   ],
   "id": "802671dbc266599e",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 1702.9466552734375\n",
      "199 1160.3759765625\n",
      "299 792.4471435546875\n",
      "399 542.67529296875\n",
      "499 372.9288330078125\n",
      "599 257.43951416015625\n",
      "699 178.77630615234375\n",
      "799 125.13536071777344\n",
      "899 88.51569366455078\n",
      "999 63.48726272583008\n",
      "1099 46.36148452758789\n",
      "1199 34.6296272277832\n",
      "1299 26.583614349365234\n",
      "1399 21.059131622314453\n",
      "1499 17.261661529541016\n",
      "1599 14.648401260375977\n",
      "1699 12.848105430603027\n",
      "1799 11.606484413146973\n",
      "1899 10.749262809753418\n",
      "1999 10.156793594360352\n",
      "Result: y = 0.03255339339375496 + 0.8374508023262024 x + -0.0056160022504627705 x^2 + -0.09058655053377151 x^3\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T14:29:10.806249Z",
     "start_time": "2024-10-11T14:29:10.603033Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "import torch\n",
    "import math\n",
    "\n",
    "dtype = torch.float\n",
    "device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
    "torch.set_default_device(device)\n",
    "\n",
    "# Create Tensors to hold input and outputs.\n",
    "# By default, requires_grad=False, which indicates that we do not need to\n",
    "# compute gradients with respect to these Tensors during the backward pass.\n",
    "x = torch.linspace(-math.pi, math.pi, 2000, dtype=dtype)\n",
    "y = torch.sin(x)\n",
    "\n",
    "# Create random Tensors for weights. For a third order polynomial, we need\n",
    "# 4 weights: y = a + b x + c x^2 + d x^3\n",
    "# Setting requires_grad=True indicates that we want to compute gradients with\n",
    "# respect to these Tensors during the backward pass.\n",
    "a = torch.randn((), dtype=dtype, requires_grad=True)\n",
    "b = torch.randn((), dtype=dtype, requires_grad=True)\n",
    "c = torch.randn((), dtype=dtype, requires_grad=True)\n",
    "d = torch.randn((), dtype=dtype, requires_grad=True)\n",
    "\n",
    "learning_rate = 1e-6\n",
    "for t in range(2000):\n",
    "    # Forward pass: compute predicted y using operations on Tensors.\n",
    "    y_pred = a + b * x + c * x ** 2 + d * x ** 3\n",
    "\n",
    "    # Compute and print loss using operations on Tensors.\n",
    "    # Now loss is a Tensor of shape (1,)\n",
    "    # loss.item() gets the scalar value held in the loss.\n",
    "    loss = (y_pred - y).pow(2).sum()\n",
    "    if t % 100 == 99:\n",
    "        print(t, loss.item())\n",
    "\n",
    "    # Use autograd to compute the backward pass. This call will compute the\n",
    "    # gradient of loss with respect to all Tensors with requires_grad=True.\n",
    "    # After this call a.grad, b.grad. c.grad and d.grad will be Tensors holding\n",
    "    # the gradient of the loss with respect to a, b, c, d respectively.\n",
    "    loss.backward()\n",
    "\n",
    "    # Manually update weights using gradient descent. Wrap in torch.no_grad()\n",
    "    # because weights have requires_grad=True, but we don't need to track this\n",
    "    # in autograd.\n",
    "    with torch.no_grad():\n",
    "        a -= learning_rate * a.grad\n",
    "        b -= learning_rate * b.grad\n",
    "        c -= learning_rate * c.grad\n",
    "        d -= learning_rate * d.grad\n",
    "\n",
    "        # Manually zero the gradients after updating weights\n",
    "        a.grad = None\n",
    "        b.grad = None\n",
    "        c.grad = None\n",
    "        d.grad = None\n",
    "\n",
    "print(f'Result: y = {a.item()} + {b.item()} x + {c.item()} x^2 + {d.item()} x^3')"
   ],
   "id": "479406c766e3332e",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 1516.8038330078125\n",
      "199 1074.79638671875\n",
      "299 762.3992919921875\n",
      "399 541.5880126953125\n",
      "499 385.501220703125\n",
      "599 275.1585693359375\n",
      "699 197.14895629882812\n",
      "799 141.99456787109375\n",
      "899 102.9969711303711\n",
      "999 75.42174530029297\n",
      "1099 55.922325134277344\n",
      "1199 42.132904052734375\n",
      "1299 32.380985260009766\n",
      "1399 25.484169006347656\n",
      "1499 20.6063175201416\n",
      "1599 17.156286239624023\n",
      "1699 14.716053009033203\n",
      "1799 12.990001678466797\n",
      "1899 11.769073486328125\n",
      "1999 10.905423164367676\n",
      "Result: y = -0.04825877770781517 + 0.8537266254425049 x + 0.008325439877808094 x^2 + -0.09290163964033127 x^3\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T14:32:06.188166Z",
     "start_time": "2024-10-11T14:32:05.967891Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "import torch\n",
    "import math\n",
    "\n",
    "\n",
    "class LegendrePolynomial3(torch.autograd.Function):\n",
    "    \"\"\"\n",
    "    We can implement our own custom autograd Functions by subclassing\n",
    "    torch.autograd.Function and implementing the forward and backward passes\n",
    "    which operate on Tensors.\n",
    "    \"\"\"\n",
    "\n",
    "    @staticmethod\n",
    "    def forward(ctx, input):\n",
    "        \"\"\"\n",
    "        In the forward pass we receive a Tensor containing the input and return\n",
    "        a Tensor containing the output. ctx is a context object that can be used\n",
    "        to stash information for backward computation. You can cache arbitrary\n",
    "        objects for use in the backward pass using the ctx.save_for_backward method.\n",
    "        \"\"\"\n",
    "        ctx.save_for_backward(input)\n",
    "        return 0.5 * (5 * input ** 3 - 3 * input)\n",
    "\n",
    "    @staticmethod\n",
    "    def backward(ctx, grad_output):\n",
    "        \"\"\"\n",
    "        In the backward pass we receive a Tensor containing the gradient of the loss\n",
    "        with respect to the output, and we need to compute the gradient of the loss\n",
    "        with respect to the input.\n",
    "        \"\"\"\n",
    "        input, = ctx.saved_tensors\n",
    "        return grad_output * 1.5 * (5 * input ** 2 - 1)\n",
    "\n",
    "\n",
    "dtype = torch.float\n",
    "device = torch.device(\"cpu\")\n",
    "# device = torch.device(\"cuda:0\")  # Uncomment this to run on GPU\n",
    "\n",
    "# Create Tensors to hold input and outputs.\n",
    "# By default, requires_grad=False, which indicates that we do not need to\n",
    "# compute gradients with respect to these Tensors during the backward pass.\n",
    "x = torch.linspace(-math.pi, math.pi, 2000, device=device, dtype=dtype)\n",
    "y = torch.sin(x)\n",
    "\n",
    "# Create random Tensors for weights. For this example, we need\n",
    "# 4 weights: y = a + b * P3(c + d * x), these weights need to be initialized\n",
    "# not too far from the correct result to ensure convergence.\n",
    "# Setting requires_grad=True indicates that we want to compute gradients with\n",
    "# respect to these Tensors during the backward pass.\n",
    "a = torch.full((), 0.0, device=device, dtype=dtype, requires_grad=True)\n",
    "b = torch.full((), -1.0, device=device, dtype=dtype, requires_grad=True)\n",
    "c = torch.full((), 0.0, device=device, dtype=dtype, requires_grad=True)\n",
    "d = torch.full((), 0.3, device=device, dtype=dtype, requires_grad=True)\n",
    "\n",
    "learning_rate = 5e-6\n",
    "for t in range(2000):\n",
    "    # To apply our Function, we use Function.apply method. We alias this as 'P3'.\n",
    "    P3 = LegendrePolynomial3.apply\n",
    "\n",
    "    # Forward pass: compute predicted y using operations; we compute\n",
    "    # P3 using our custom autograd operation.\n",
    "    y_pred = a + b * P3(c + d * x)\n",
    "\n",
    "    # Compute and print loss\n",
    "    loss = (y_pred - y).pow(2).sum()\n",
    "    if t % 100 == 99:\n",
    "        print(t, loss.item())\n",
    "\n",
    "    # Use autograd to compute the backward pass.\n",
    "    loss.backward()\n",
    "\n",
    "    # Update weights using gradient descent\n",
    "    with torch.no_grad():\n",
    "        a -= learning_rate * a.grad\n",
    "        b -= learning_rate * b.grad\n",
    "        c -= learning_rate * c.grad\n",
    "        d -= learning_rate * d.grad\n",
    "\n",
    "        # Manually zero the gradients after updating weights\n",
    "        a.grad = None\n",
    "        b.grad = None\n",
    "        c.grad = None\n",
    "        d.grad = None\n",
    "\n",
    "print(f'Result: y = {a.item()} + {b.item()} * P3({c.item()} + {d.item()} x)')"
   ],
   "id": "2b3c6e831111efb",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 209.95834350585938\n",
      "199 144.66018676757812\n",
      "299 100.70249938964844\n",
      "399 71.03519439697266\n",
      "499 50.97850799560547\n",
      "599 37.403133392333984\n",
      "699 28.206867218017578\n",
      "799 21.97318458557129\n",
      "899 17.7457275390625\n",
      "999 14.877889633178711\n",
      "1099 12.93176555633545\n",
      "1199 11.610918998718262\n",
      "1299 10.714258193969727\n",
      "1399 10.105483055114746\n",
      "1499 9.692106246948242\n",
      "1599 9.411375999450684\n",
      "1699 9.220745086669922\n",
      "1799 9.091285705566406\n",
      "1899 9.003361701965332\n",
      "1999 8.943641662597656\n",
      "Result: y = -5.901059640933681e-10 + -2.208526849746704 * P3(-2.725097647537922e-10 + 0.2554861009120941 x)\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T14:36:16.565460Z",
     "start_time": "2024-10-11T14:36:16.421790Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "import torch\n",
    "import math\n",
    "\n",
    "\n",
    "# Create Tensors to hold input and outputs.\n",
    "x = torch.linspace(-math.pi, math.pi, 2000)\n",
    "y = torch.sin(x)\n",
    "\n",
    "# For this example, the output y is a linear function of (x, x^2, x^3), so\n",
    "# we can consider it as a linear layer neural network. Let's prepare the\n",
    "# tensor (x, x^2, x^3).\n",
    "p = torch.tensor([1, 2, 3])\n",
    "xx = x.unsqueeze(-1).pow(p)\n",
    "\n",
    "# In the above code, x.unsqueeze(-1) has shape (2000, 1), and p has shape\n",
    "# (3,), for this case, broadcasting semantics will apply to obtain a tensor\n",
    "# of shape (2000, 3) \n",
    "\n",
    "# Use the nn package to define our model as a sequence of layers. nn.Sequential\n",
    "# is a Module which contains other Modules, and applies them in sequence to\n",
    "# produce its output. The Linear Module computes output from input using a\n",
    "# linear function, and holds internal Tensors for its weight and bias.\n",
    "# The Flatten layer flatens the output of the linear layer to a 1D tensor,\n",
    "# to match the shape of `y`.\n",
    "model = torch.nn.Sequential(\n",
    "    torch.nn.Linear(3, 1),\n",
    "    torch.nn.Flatten(0, 1)\n",
    ")\n",
    "\n",
    "# The nn package also contains definitions of popular loss functions; in this\n",
    "# case we will use Mean Squared Error (MSE) as our loss function.\n",
    "loss_fn = torch.nn.MSELoss(reduction='sum')\n",
    "\n",
    "learning_rate = 1e-6\n",
    "for t in range(2000):\n",
    "\n",
    "    # Forward pass: compute predicted y by passing x to the model. Module objects\n",
    "    # override the __call__ operator so you can call them like functions. When\n",
    "    # doing so you pass a Tensor of input data to the Module and it produces\n",
    "    # a Tensor of output data.\n",
    "    y_pred = model(xx)\n",
    "\n",
    "    # Compute and print loss. We pass Tensors containing the predicted and true\n",
    "    # values of y, and the loss function returns a Tensor containing the\n",
    "    # loss.\n",
    "    loss = loss_fn(y_pred, y)\n",
    "    if t % 100 == 99:\n",
    "        print(t, loss.item())\n",
    "\n",
    "    # Zero the gradients before running the backward pass.\n",
    "    model.zero_grad()\n",
    "\n",
    "    # Backward pass: compute gradient of the loss with respect to all the learnable\n",
    "    # parameters of the model. Internally, the parameters of each Module are stored\n",
    "    # in Tensors with requires_grad=True, so this call will compute gradients for\n",
    "    # all learnable parameters in the model.\n",
    "    loss.backward()\n",
    "\n",
    "    # Update the weights using gradient descent. Each parameter is a Tensor, so\n",
    "    # we can access its gradients like we did before.\n",
    "    with torch.no_grad():\n",
    "        for param in model.parameters():\n",
    "            param -= learning_rate * param.grad\n",
    "\n",
    "# You can access the first layer of `model` like accessing the first item of a list\n",
    "linear_layer = model[0]\n",
    "\n",
    "# For linear layer, its parameters are stored as `weight` and `bias`.\n",
    "print(f'Result: y = {linear_layer.bias.item()} + {linear_layer.weight[:, 0].item()} x + {linear_layer.weight[:, 1].item()} x^2 + {linear_layer.weight[:, 2].item()} x^3')"
   ],
   "id": "fc99e04aee2a5cc4",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 602.0060424804688\n",
      "199 405.01690673828125\n",
      "299 273.60198974609375\n",
      "399 185.88601684570312\n",
      "499 127.30487060546875\n",
      "599 88.15865325927734\n",
      "699 61.98329544067383\n",
      "799 44.469810485839844\n",
      "899 32.74373245239258\n",
      "999 24.887277603149414\n",
      "1099 19.619417190551758\n",
      "1199 16.08468246459961\n",
      "1299 13.710931777954102\n",
      "1399 12.115535736083984\n",
      "1499 11.042346000671387\n",
      "1599 10.319786071777344\n",
      "1699 9.832869529724121\n",
      "1799 9.504432678222656\n",
      "1899 9.282690048217773\n",
      "1999 9.132826805114746\n",
      "Result: y = -0.01156605500727892 + 0.8431226015090942 x + 0.0019953364972025156 x^2 + -0.09139330685138702 x^3\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T14:37:27.219313Z",
     "start_time": "2024-10-11T14:37:26.569589Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "import torch\n",
    "import math\n",
    "\n",
    "\n",
    "# Create Tensors to hold input and outputs.\n",
    "x = torch.linspace(-math.pi, math.pi, 2000)\n",
    "y = torch.sin(x)\n",
    "\n",
    "# Prepare the input tensor (x, x^2, x^3).\n",
    "p = torch.tensor([1, 2, 3])\n",
    "xx = x.unsqueeze(-1).pow(p)\n",
    "\n",
    "# Use the nn package to define our model and loss function.\n",
    "model = torch.nn.Sequential(\n",
    "    torch.nn.Linear(3, 1),\n",
    "    torch.nn.Flatten(0, 1)\n",
    ")\n",
    "loss_fn = torch.nn.MSELoss(reduction='sum')\n",
    "\n",
    "# Use the optim package to define an Optimizer that will update the weights of\n",
    "# the model for us. Here we will use RMSprop; the optim package contains many other\n",
    "# optimization algorithms. The first argument to the RMSprop constructor tells the\n",
    "# optimizer which Tensors it should update.\n",
    "learning_rate = 1e-3\n",
    "optimizer = torch.optim.RMSprop(model.parameters(), lr=learning_rate)\n",
    "for t in range(2000):\n",
    "    # Forward pass: compute predicted y by passing x to the model.\n",
    "    y_pred = model(xx)\n",
    "\n",
    "    # Compute and print loss.\n",
    "    loss = loss_fn(y_pred, y)\n",
    "    if t % 100 == 99:\n",
    "        print(t, loss.item())\n",
    "\n",
    "    # Before the backward pass, use the optimizer object to zero all of the\n",
    "    # gradients for the variables it will update (which are the learnable\n",
    "    # weights of the model). This is because by default, gradients are\n",
    "    # accumulated in buffers( i.e, not overwritten) whenever .backward()\n",
    "    # is called. Checkout docs of torch.autograd.backward for more details.\n",
    "    optimizer.zero_grad()\n",
    "\n",
    "    # Backward pass: compute gradient of the loss with respect to model\n",
    "    # parameters\n",
    "    loss.backward()\n",
    "\n",
    "    # Calling the step function on an Optimizer makes an update to its\n",
    "    # parameters\n",
    "    optimizer.step()\n",
    "\n",
    "\n",
    "linear_layer = model[0]\n",
    "print(f'Result: y = {linear_layer.bias.item()} + {linear_layer.weight[:, 0].item()} x + {linear_layer.weight[:, 1].item()} x^2 + {linear_layer.weight[:, 2].item()} x^3')"
   ],
   "id": "f61c9c2490154174",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 429.923828125\n",
      "199 277.619873046875\n",
      "299 194.3204345703125\n",
      "399 126.20797729492188\n",
      "499 75.40357971191406\n",
      "599 41.73927307128906\n",
      "699 22.08734893798828\n",
      "799 12.566656112670898\n",
      "899 9.378151893615723\n",
      "999 8.844072341918945\n",
      "1099 9.199462890625\n",
      "1199 8.819156646728516\n",
      "1299 8.829143524169922\n",
      "1399 8.857532501220703\n",
      "1499 8.933923721313477\n",
      "1599 8.9342041015625\n",
      "1699 8.896539688110352\n",
      "1799 8.899118423461914\n",
      "1899 8.91447639465332\n",
      "1999 8.91702651977539\n",
      "Result: y = -0.00036004831781610847 + 0.8572483658790588 x + -0.0003600661875680089 x^2 + -0.09282271564006805 x^3\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T14:40:06.913454Z",
     "start_time": "2024-10-11T14:40:06.661274Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "import torch\n",
    "import math\n",
    "\n",
    "\n",
    "class Polynomial3(torch.nn.Module):\n",
    "    def __init__(self):\n",
    "        \"\"\"\n",
    "        In the constructor we instantiate four parameters and assign them as\n",
    "        member parameters.\n",
    "        \"\"\"\n",
    "        super().__init__()\n",
    "        self.a = torch.nn.Parameter(torch.randn(()))\n",
    "        self.b = torch.nn.Parameter(torch.randn(()))\n",
    "        self.c = torch.nn.Parameter(torch.randn(()))\n",
    "        self.d = torch.nn.Parameter(torch.randn(()))\n",
    "\n",
    "    def forward(self, x):\n",
    "        \"\"\"\n",
    "        In the forward function we accept a Tensor of input data and we must return\n",
    "        a Tensor of output data. We can use Modules defined in the constructor as\n",
    "        well as arbitrary operators on Tensors.\n",
    "        \"\"\"\n",
    "        return self.a + self.b * x + self.c * x ** 2 + self.d * x ** 3\n",
    "\n",
    "    def string(self):\n",
    "        \"\"\"\n",
    "        Just like any class in Python, you can also define custom method on PyTorch modules\n",
    "        \"\"\"\n",
    "        return f'y = {self.a.item()} + {self.b.item()} x + {self.c.item()} x^2 + {self.d.item()} x^3'\n",
    "\n",
    "\n",
    "# Create Tensors to hold input and outputs.\n",
    "x = torch.linspace(-math.pi, math.pi, 2000)\n",
    "y = torch.sin(x)\n",
    "\n",
    "# Construct our model by instantiating the class defined above\n",
    "model = Polynomial3()\n",
    "\n",
    "# Construct our loss function and an Optimizer. The call to model.parameters()\n",
    "# in the SGD constructor will contain the learnable parameters (defined \n",
    "# with torch.nn.Parameter) which are members of the model.\n",
    "criterion = torch.nn.MSELoss(reduction='sum')\n",
    "optimizer = torch.optim.SGD(model.parameters(), lr=1e-6)\n",
    "for t in range(2000):\n",
    "    # Forward pass: Compute predicted y by passing x to the model\n",
    "    y_pred = model(x)\n",
    "\n",
    "    # Compute and print loss\n",
    "    loss = criterion(y_pred, y)\n",
    "    if t % 100 == 99:\n",
    "        print(t, loss.item())\n",
    "\n",
    "    # Zero gradients, perform a backward pass, and update the weights.\n",
    "    optimizer.zero_grad()\n",
    "    loss.backward()\n",
    "    optimizer.step()\n",
    "\n",
    "print(f'Result: {model.string()}')"
   ],
   "id": "a1d242ea82d136e1",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 828.6395874023438\n",
      "199 584.45703125\n",
      "299 413.1882019042969\n",
      "399 292.99969482421875\n",
      "499 208.61599731445312\n",
      "599 149.34339904785156\n",
      "699 107.69091796875\n",
      "799 78.40850830078125\n",
      "899 57.814414978027344\n",
      "999 43.32539367675781\n",
      "1099 33.12800979614258\n",
      "1199 25.948768615722656\n",
      "1299 20.89275550842285\n",
      "1399 17.33098030090332\n",
      "1499 14.82115650177002\n",
      "1599 13.052151679992676\n",
      "1699 11.804954528808594\n",
      "1799 10.925464630126953\n",
      "1899 10.305126190185547\n",
      "1999 9.867493629455566\n",
      "Result: y = -0.03368539735674858 + 0.8507835268974304 x + 0.005811292212456465 x^2 + -0.09248301386833191 x^3\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T14:41:53.163370Z",
     "start_time": "2024-10-11T14:41:48.192151Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "import random\n",
    "import torch\n",
    "import math\n",
    "\n",
    "\n",
    "class DynamicNet(torch.nn.Module):\n",
    "    def __init__(self):\n",
    "        \"\"\"\n",
    "        In the constructor we instantiate five parameters and assign them as members.\n",
    "        \"\"\"\n",
    "        super().__init__()\n",
    "        self.a = torch.nn.Parameter(torch.randn(()))\n",
    "        self.b = torch.nn.Parameter(torch.randn(()))\n",
    "        self.c = torch.nn.Parameter(torch.randn(()))\n",
    "        self.d = torch.nn.Parameter(torch.randn(()))\n",
    "        self.e = torch.nn.Parameter(torch.randn(()))\n",
    "\n",
    "    def forward(self, x):\n",
    "        \"\"\"\n",
    "        For the forward pass of the model, we randomly choose either 4, 5\n",
    "        and reuse the e parameter to compute the contribution of these orders.\n",
    "\n",
    "        Since each forward pass builds a dynamic computation graph, we can use normal\n",
    "        Python control-flow operators like loops or conditional statements when\n",
    "        defining the forward pass of the model.\n",
    "\n",
    "        Here we also see that it is perfectly safe to reuse the same parameter many\n",
    "        times when defining a computational graph.\n",
    "        \"\"\"\n",
    "        y = self.a + self.b * x + self.c * x ** 2 + self.d * x ** 3\n",
    "        for exp in range(4, random.randint(4, 6)):\n",
    "            y = y + self.e * x ** exp\n",
    "        return y\n",
    "\n",
    "    def string(self):\n",
    "        \"\"\"\n",
    "        Just like any class in Python, you can also define custom method on PyTorch modules\n",
    "        \"\"\"\n",
    "        return f'y = {self.a.item()} + {self.b.item()} x + {self.c.item()} x^2 + {self.d.item()} x^3 + {self.e.item()} x^4 ? + {self.e.item()} x^5 ?'\n",
    "\n",
    "\n",
    "# Create Tensors to hold input and outputs.\n",
    "x = torch.linspace(-math.pi, math.pi, 2000)\n",
    "y = torch.sin(x)\n",
    "\n",
    "# Construct our model by instantiating the class defined above\n",
    "model = DynamicNet()\n",
    "\n",
    "# Construct our loss function and an Optimizer. Training this strange model with\n",
    "# vanilla stochastic gradient descent is tough, so we use momentum\n",
    "criterion = torch.nn.MSELoss(reduction='sum')\n",
    "optimizer = torch.optim.SGD(model.parameters(), lr=1e-8, momentum=0.9)\n",
    "for t in range(30000):\n",
    "    # Forward pass: Compute predicted y by passing x to the model\n",
    "    y_pred = model(x)\n",
    "\n",
    "    # Compute and print loss\n",
    "    loss = criterion(y_pred, y)\n",
    "    if t % 2000 == 1999:\n",
    "        print(t, loss.item())\n",
    "\n",
    "    # Zero gradients, perform a backward pass, and update the weights.\n",
    "    optimizer.zero_grad()\n",
    "    loss.backward()\n",
    "    optimizer.step()\n",
    "\n",
    "print(f'Result: {model.string()}')"
   ],
   "id": "244809eafd348403",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1999 163.96177673339844\n",
      "3999 85.12416076660156\n",
      "5999 46.337833404541016\n",
      "7999 27.214252471923828\n",
      "9999 17.808082580566406\n",
      "11999 13.444267272949219\n",
      "13999 11.188623428344727\n",
      "15999 9.9386568069458\n",
      "17999 9.429798126220703\n",
      "19999 8.836661338806152\n",
      "21999 9.017271041870117\n",
      "23999 8.651689529418945\n",
      "25999 8.892016410827637\n",
      "27999 8.60377311706543\n",
      "29999 8.578250885009766\n",
      "Result: y = -0.002438504481688142 + 0.8580242395401001 x + -6.698395009152591e-05 x^2 + -0.09380234032869339 x^3 + 0.00012265393161214888 x^4 ? + 0.00012265393161214888 x^5 ?\n"
     ]
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T14:44:24.786025Z",
     "start_time": "2024-10-11T14:44:24.675Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import numpy as np\n",
    "import math\n",
    "\n",
    "# Create random input and output data\n",
    "x = np.linspace(-math.pi, math.pi, 2000)\n",
    "y = np.sin(x)\n",
    "\n",
    "# Randomly initialize weights\n",
    "a = np.random.randn()\n",
    "b = np.random.randn()\n",
    "c = np.random.randn()\n",
    "d = np.random.randn()\n",
    "\n",
    "learning_rate = 1e-6\n",
    "for t in range(2000):\n",
    "    # Forward pass: compute predicted y\n",
    "    # y = a + b x + c x^2 + d x^3\n",
    "    y_pred = a + b * x + c * x ** 2 + d * x ** 3\n",
    "\n",
    "    # Compute and print loss\n",
    "    loss = np.square(y_pred - y).sum()\n",
    "    if t % 100 == 99:\n",
    "        print(t, loss)\n",
    "\n",
    "    # Backprop to compute gradients of a, b, c, d with respect to loss\n",
    "    grad_y_pred = 2.0 * (y_pred - y)\n",
    "    grad_a = grad_y_pred.sum()\n",
    "    grad_b = (grad_y_pred * x).sum()\n",
    "    grad_c = (grad_y_pred * x ** 2).sum()\n",
    "    grad_d = (grad_y_pred * x ** 3).sum()\n",
    "\n",
    "    # Update weights\n",
    "    a -= learning_rate * grad_a\n",
    "    b -= learning_rate * grad_b\n",
    "    c -= learning_rate * grad_c\n",
    "    d -= learning_rate * grad_d\n",
    "\n",
    "print(f'Result: y = {a} + {b} x + {c} x^2 + {d} x^3')"
   ],
   "id": "7e13b6070e0999d2",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 39.151556372958325\n",
      "199 30.274324916973065\n",
      "299 23.996948893350055\n",
      "399 19.556250669063285\n",
      "499 16.4147724106687\n",
      "599 14.192353582708785\n",
      "699 12.620086868467716\n",
      "799 11.507754832021286\n",
      "899 10.72079952475672\n",
      "999 10.164033651315348\n",
      "1099 9.770119473654422\n",
      "1199 9.491419671382772\n",
      "1299 9.29423308940407\n",
      "1399 9.154717307025301\n",
      "1499 9.056004328679403\n",
      "1599 8.986160218819503\n",
      "1699 8.936741710604938\n",
      "1799 8.901775102394058\n",
      "1899 8.877033880074286\n",
      "1999 8.859527662646002\n",
      "Result: y = -0.006884729762352859 + 0.8565100275003902 x + 0.0011877304464036193 x^2 + -0.09329755753524321 x^3\n"
     ]
    }
   ],
   "execution_count": 9
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# What is torch.nn really?",
   "id": "3bc76333ba63134c"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T14:55:51.808748Z",
     "start_time": "2024-10-11T14:55:48.693613Z"
    }
   },
   "cell_type": "code",
   "source": "!pip install pathlib",
   "id": "4fb681a2b7feb99f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting pathlib\r\n",
      "  Downloading pathlib-1.0.1-py3-none-any.whl.metadata (5.1 kB)\r\n",
      "Downloading pathlib-1.0.1-py3-none-any.whl (14 kB)\r\n",
      "Installing collected packages: pathlib\r\n",
      "Successfully installed pathlib-1.0.1\r\n"
     ]
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# Visualizing Models, Data, and Training with TensorBoard",
   "id": "3c1be3e5a2233876"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T15:26:06.902110Z",
     "start_time": "2024-10-11T15:26:02.225015Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# imports\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "import torch\n",
    "import torchvision\n",
    "import torchvision.transforms as transforms\n",
    "\n",
    "import torch.nn as nn\n",
    "import torch.nn.functional as F\n",
    "import torch.optim as optim\n",
    "\n",
    "# transforms\n",
    "transform = transforms.Compose(\n",
    "    [transforms.ToTensor(),\n",
    "    transforms.Normalize((0.5,), (0.5,))])\n",
    "\n",
    "# datasets\n",
    "trainset = torchvision.datasets.FashionMNIST('./data',\n",
    "    download=True,\n",
    "    train=True,\n",
    "    transform=transform)\n",
    "testset = torchvision.datasets.FashionMNIST('./data',\n",
    "    download=True,\n",
    "    train=False,\n",
    "    transform=transform)\n",
    "\n",
    "# dataloaders\n",
    "trainloader = torch.utils.data.DataLoader(trainset, batch_size=4,\n",
    "                                        shuffle=True, num_workers=2)\n",
    "\n",
    "\n",
    "testloader = torch.utils.data.DataLoader(testset, batch_size=4,\n",
    "                                        shuffle=False, num_workers=2)\n",
    "\n",
    "# constant for classes\n",
    "classes = ('T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',\n",
    "        'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle Boot')\n",
    "\n",
    "# helper function to show an image\n",
    "# (used in the `plot_classes_preds` function below)\n",
    "def matplotlib_imshow(img, one_channel=False):\n",
    "    if one_channel:\n",
    "        img = img.mean(dim=0)\n",
    "    img = img / 2 + 0.5     # unnormalize\n",
    "    npimg = img.numpy()\n",
    "    if one_channel:\n",
    "        plt.imshow(npimg, cmap=\"Greys\")\n",
    "    else:\n",
    "        plt.imshow(np.transpose(npimg, (1, 2, 0)))\n",
    "        \n",
    "        \n",
    "class Net(nn.Module):\n",
    "    def __init__(self):\n",
    "        super(Net, self).__init__()\n",
    "        self.conv1 = nn.Conv2d(1, 6, 5)\n",
    "        self.pool = nn.MaxPool2d(2, 2)\n",
    "        self.conv2 = nn.Conv2d(6, 16, 5)\n",
    "        self.fc1 = nn.Linear(16 * 4 * 4, 120)\n",
    "        self.fc2 = nn.Linear(120, 84)\n",
    "        self.fc3 = nn.Linear(84, 10)\n",
    "\n",
    "    def forward(self, x):\n",
    "        x = self.pool(F.relu(self.conv1(x)))\n",
    "        x = self.pool(F.relu(self.conv2(x)))\n",
    "        x = x.view(-1, 16 * 4 * 4)\n",
    "        x = F.relu(self.fc1(x))\n",
    "        x = F.relu(self.fc2(x))\n",
    "        x = self.fc3(x)\n",
    "        return x\n",
    "\n",
    "\n",
    "net = Net()\n",
    "\n",
    "\n",
    "criterion = nn.CrossEntropyLoss()\n",
    "optimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9)\n",
    "\n",
    "from torch.utils.tensorboard import SummaryWriter\n",
    "\n",
    "# default `log_dir` is \"runs\" - we'll be more specific here\n",
    "writer = SummaryWriter('runs/fashion_mnist_experiment_1')\n",
    "\n",
    "# get some random training images\n",
    "dataiter = iter(trainloader)\n",
    "images, labels = next(dataiter)\n",
    "\n",
    "# create grid of images\n",
    "img_grid = torchvision.utils.make_grid(images)\n",
    "\n",
    "# show images\n",
    "matplotlib_imshow(img_grid, one_channel=True)\n",
    "\n",
    "# write to tensorboard\n",
    "writer.add_image('four_fashion_mnist_images', img_grid)"
   ],
   "id": "193a89ecefef1d61",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ],
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAiYAAACxCAYAAADwMnaUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAoBklEQVR4nO3de3RU1fk38CfchgRCIIRkMuRi0HATRQk0BVkSFUKRar2sVqUCim1BhJKm/XF1LaPFBNFS29rgZSnaWoR2CQpVkVAhgFSBQARBuZQACSRGLrkgIQGy3z98M4v9PcPsGTIhJ5nvZy3+eGbOnHNmn0s2Zz/z7BCllBIiIiIiG2jT3DtARERE1IAdEyIiIrINdkyIiIjINtgxISIiIttgx4SIiIhsgx0TIiIisg12TIiIiMg22DEhIiIi22DHhIiIiGyDHRMiIiKyjSbrmOTm5kpSUpJ07NhRUlJSZNOmTU21KSIiImol2jXFSpcvXy4ZGRmSm5srt9xyi7zyyisyZswY2bt3ryQkJHj9bH19vRw/flzCw8MlJCSkKXaPiIiIAkwpJdXV1eJyuaRNmyt/7hHSFJP4paamyqBBg2Tx4sXu1/r16yf33HOP5OTkeP1sSUmJxMfHB3qXiIiI6CooLi6WuLi4K/58wJ+Y1NXVSUFBgcyePVt7PT09XbZs2WJZvra2Vmpra91xQz9p/vz50rFjx0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d+ipKREi6OiorQYJ0vbvn27FmMBJxwjPnz4sBabCu+YCkBdd911Xpffu3evFnvKjejevbsWl5WVaTEWjbva/M2FwO9z//33e409ee2117y+f+7cOS3GMWR8HwthNfXEiL7ke5jG2fF9f/OjrjZfciNwUs64uDgtxlwCvEfs2LFDi/F6M02yh22I72NOCm5/4MCBWowFIdPS0gRhDhlqjTklCPPmMBcH7xk4id5HH33k1/by8/O1GPMZ8bjh34FPP/3Ur+21FnxiQkRERLbBjgkRERHZBjsmREREZBvMMRGRKVOmWF7r06ePFo8ePVqLcYx49erVWmwaI8axf1yfpwnmLoVj0jimjbkLf/nLX7QY63WIWCfN27Ztmxbfe++9XvepqdlxDBzrTyCsg9AS2K2d/c0twmvL0ySdeL397W9/02K8fisqKrQYc8awPgZe77g85hLg9RoWFqbFWHMEr1+ss3Ql/M01aolef/11LX711Ve1GHNIhgwZosWmukFo1apVWvzHP/5Ri7/44gstxvsJ/l0JFnxiQkRERLbhV8dk8eLFcuONN0qXLl2kS5cuMnToUK2HqZSSrKwscblcEhoaKmlpabJnz56A7zQRERG1Tn51TOLi4mTBggWyfft22b59u9x+++3yk5/8xN35WLhwoSxatEheeukl2bZtmzidThk1apTHku9EREREKER5GoD1Q2RkpDz//PMyadIkcblckpGRIbNmzRKR78dpY2Ji5LnnnpPJkyf7tL6qqiqJiIiQF154wWMeBBEREdlPTU2N/O53v5PKykpLjRZ/XHGOycWLF2XZsmXy3XffydChQ6WoqEjKysokPT3dvYzD4ZARI0bIli1bLrue2tpaqaqq0v4RERFRcPK7Y7J7927p3LmzOBwOmTJliqxcuVL69+/vrhIaExOjLR8TE2OpIHqpnJwciYiIcP+Lj4/3d5eIiIiolfC7Y9KnTx8pLCyUzz77TB5//HGZOHGiVu7c00/OvP3MbM6cOVJZWen+V1xc7O8uERERUSvhdx2TDh06uOdlGTx4sGzbtk3+9Kc/ufNKysrKJDY21r18eXm55SnKpRwOh7FmBxEREQWHRtcxUUpJbW2tJCUlidPplLy8PPd7dX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/vKlvZxOp9TV1cnp06cvuwx97/z58/Kzn/1MioqKJC8vz/20RCRw7Wi7jkmHDh0kJSVF8vLytNfz8vJk2LBhzbRX9qaUkmnTpsmKFSvkk08+kaSkJO39pKQkcTqdWpvW1dVJfn4+2/T/u+OOO2T37t1SWFjo/jd48GD5+c9/LoWFhdKrVy+2oQ9uueUWy0/V9+/fL4mJiSLCc9EXZ8+elTZt9Ftz27Zt3T8XZhv6x5f2SklJkfbt22vLlJaWypdffsk2vURDp+TAgQOybt066d69u/Z+wNrRjyTdq6bh58Kvv/662rt3r8rIyFCdOnVShw8fbu5ds6XHH39cRUREqA0bNqjS0lL3v7Nnz7qXWbBggYqIiFArVqxQu3fvVg899FBQ/7zQF5f+KkcptqEvtm7dqtq1a6eeffZZdeDAAfWPf/xDhYWFqbffftu9DNvRu4kTJ6qePXu6fy68YsUKFRUVpWbOnOlehm2oq66uVjt37lQ7d+5UIqIWLVqkdu7c6f61iC/tNWXKFBUXF6fWrVunduzYoW6//fag+7mwt3Y8f/68uvvuu1VcXJwqLCzU/tbU1ta61xGIdrRlx0Qppf7617+qxMRE1aFDBzVo0CD3T1/JSkQ8/luyZIl7mfr6evXUU08pp9OpHA6HuvXWW9Xu3bubb6dbAOyYsA19s3r1ajVgwADlcDhU37591auvvqq9z3b0rqqqSs2YMUMlJCSojh07ql69eql58+ZpN3+2oW79+vUe74ETJ05USvnWXjU1NWratGkqMjJShYaGqh//+Mfq6NGjzfBtmo+3diwqKrrs35r169e71xGIdgxRSil/H+cQERERNQXb5ZgQERFR8GLHhIiIiGyDHRMiIiKyDXZMiIiIyDbYMSEiIiLbYMeEiIiIbIMdEyIiIrINdkyIiIjINtgxISIiIttgx4SIiIhsgx0TIiIisg12TIiIiMg2/h+6HsGPFwA9WgAAAABJRU5ErkJggg=="
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "execution_count": 12
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T15:28:50.159Z",
     "start_time": "2024-10-11T15:28:50.081392Z"
    }
   },
   "cell_type": "code",
   "source": [
    "writer.add_graph(net, images)\n",
    "writer.close()"
   ],
   "id": "6d222bafe05bc774",
   "outputs": [],
   "execution_count": 13
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T15:31:27.127470Z",
     "start_time": "2024-10-11T15:31:27.077980Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# helper function\n",
    "def select_n_random(data, labels, n=100):\n",
    "    '''\n",
    "    Selects n random datapoints and their corresponding labels from a dataset\n",
    "    '''\n",
    "    assert len(data) == len(labels)\n",
    "\n",
    "    perm = torch.randperm(len(data))\n",
    "    return data[perm][:n], labels[perm][:n]\n",
    "\n",
    "# select random images and their target indices\n",
    "images, labels = select_n_random(trainset.data, trainset.targets)\n",
    "\n",
    "# get the class labels for each image\n",
    "class_labels = [classes[lab] for lab in labels]\n",
    "\n",
    "# log embeddings\n",
    "features = images.view(-1, 28 * 28)\n",
    "writer.add_embedding(features,\n",
    "                    metadata=class_labels,\n",
    "                    label_img=images.unsqueeze(1))\n",
    "writer.close()"
   ],
   "id": "b99c08e5730e70bf",
   "outputs": [],
   "execution_count": 14
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T15:36:53.687970Z",
     "start_time": "2024-10-11T15:36:33.703852Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# helper functions\n",
    "\n",
    "def images_to_probs(net, images):\n",
    "    '''\n",
    "    Generates predictions and corresponding probabilities from a trained\n",
    "    network and a list of images\n",
    "    '''\n",
    "    output = net(images)\n",
    "    # convert output probabilities to predicted class\n",
    "    _, preds_tensor = torch.max(output, 1)\n",
    "    preds = np.squeeze(preds_tensor.numpy())\n",
    "    return preds, [F.softmax(el, dim=0)[i].item() for i, el in zip(preds, output)]\n",
    "\n",
    "\n",
    "def plot_classes_preds(net, images, labels):\n",
    "    '''\n",
    "    Generates matplotlib Figure using a trained network, along with images\n",
    "    and labels from a batch, that shows the network's top prediction along\n",
    "    with its probability, alongside the actual label, coloring this\n",
    "    information based on whether the prediction was correct or not.\n",
    "    Uses the \"images_to_probs\" function.\n",
    "    '''\n",
    "    preds, probs = images_to_probs(net, images)\n",
    "    # plot the images in the batch, along with predicted and true labels\n",
    "    fig = plt.figure(figsize=(12, 48))\n",
    "    for idx in np.arange(4):\n",
    "        ax = fig.add_subplot(1, 4, idx+1, xticks=[], yticks=[])\n",
    "        matplotlib_imshow(images[idx], one_channel=True)\n",
    "        ax.set_title(\"{0}, {1:.1f}%\\n(label: {2})\".format(\n",
    "            classes[preds[idx]],\n",
    "            probs[idx] * 100.0,\n",
    "            classes[labels[idx]]),\n",
    "                    color=(\"green\" if preds[idx]==labels[idx].item() else \"red\"))\n",
    "    return fig\n",
    "\n",
    "\n",
    "running_loss = 0.0\n",
    "for epoch in range(1):  # loop over the dataset multiple times\n",
    "\n",
    "    for i, data in enumerate(trainloader, 0):\n",
    "\n",
    "        # get the inputs; data is a list of [inputs, labels]\n",
    "        inputs, labels = data\n",
    "\n",
    "        # zero the parameter gradients\n",
    "        optimizer.zero_grad()\n",
    "\n",
    "        # forward + backward + optimize\n",
    "        outputs = net(inputs)\n",
    "        loss = criterion(outputs, labels)\n",
    "        loss.backward()\n",
    "        optimizer.step()\n",
    "\n",
    "        running_loss += loss.item()\n",
    "        if i % 1000 == 999:    # every 1000 mini-batches...\n",
    "\n",
    "            # ...log the running loss\n",
    "            writer.add_scalar('training loss',\n",
    "                            running_loss / 1000,\n",
    "                            epoch * len(trainloader) + i)\n",
    "\n",
    "            # ...log a Matplotlib Figure showing the model's predictions on a\n",
    "            # random mini-batch\n",
    "            writer.add_figure('predictions vs. actuals',\n",
    "                            plot_classes_preds(net, inputs, labels),\n",
    "                            global_step=epoch * len(trainloader) + i)\n",
    "            running_loss = 0.0\n",
    "print('Finished Training')"
   ],
   "id": "e476590038d3b30d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Finished Training\n"
     ]
    }
   ],
   "execution_count": 15
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-11T15:39:41.753383Z",
     "start_time": "2024-10-11T15:39:39.046135Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 1. gets the probability predictions in a test_size x num_classes Tensor\n",
    "# 2. gets the preds in a test_size Tensor\n",
    "# takes ~10 seconds to run\n",
    "class_probs = []\n",
    "class_label = []\n",
    "with torch.no_grad():\n",
    "    for data in testloader:\n",
    "        images, labels = data\n",
    "        output = net(images)\n",
    "        class_probs_batch = [F.softmax(el, dim=0) for el in output]\n",
    "\n",
    "        class_probs.append(class_probs_batch)\n",
    "        class_label.append(labels)\n",
    "\n",
    "test_probs = torch.cat([torch.stack(batch) for batch in class_probs])\n",
    "test_label = torch.cat(class_label)\n",
    "\n",
    "# helper function\n",
    "def add_pr_curve_tensorboard(class_index, test_probs, test_label, global_step=0):\n",
    "    '''\n",
    "    Takes in a \"class_index\" from 0 to 9 and plots the corresponding\n",
    "    precision-recall curve\n",
    "    '''\n",
    "    tensorboard_truth = test_label == class_index\n",
    "    tensorboard_probs = test_probs[:, class_index]\n",
    "\n",
    "    writer.add_pr_curve(classes[class_index],\n",
    "                        tensorboard_truth,\n",
    "                        tensorboard_probs,\n",
    "                        global_step=global_step)\n",
    "    writer.close()\n",
    "\n",
    "# plot all the pr curves\n",
    "for i in range(len(classes)):\n",
    "    add_pr_curve_tensorboard(i, test_probs, test_label)"
   ],
   "id": "1414f1a3305b6b40",
   "outputs": [],
   "execution_count": 16
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# A guide on good usage of non_blocking and pin_memory() in PyTorch",
   "id": "d098f9370a6d2d46"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-12T14:56:03.955362Z",
     "start_time": "2024-10-12T14:56:02.788534Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import torch\n",
    "import gc\n",
    "from torch.utils.benchmark import Timer\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "\n",
    "def timer(cmd):\n",
    "    median = (\n",
    "        Timer(cmd, globals=globals())\n",
    "        .adaptive_autorange(min_run_time=1.0, max_run_time=20.0)\n",
    "        .median\n",
    "        * 1000\n",
    "    )\n",
    "    print(f\"{cmd}: {median: 4.4f} ms\")\n",
    "    return median\n",
    "\n",
    "\n",
    "# A tensor in pageable memory\n",
    "pageable_tensor = torch.randn(1_000_000)\n",
    "\n",
    "# A tensor in page-locked (pinned) memory\n",
    "pinned_tensor = torch.randn(1_000_000, pin_memory=True)\n",
    "\n",
    "# Runtimes:\n",
    "pageable_to_device = timer(\"pageable_tensor.to('cuda:0')\")\n",
    "pinned_to_device = timer(\"pinned_tensor.to('cuda:0')\")\n",
    "pin_mem = timer(\"pageable_tensor.pin_memory()\")\n",
    "pin_mem_to_device = timer(\"pageable_tensor.pin_memory().to('cuda:0')\")\n",
    "\n",
    "# Ratios:\n",
    "r1 = pinned_to_device / pageable_to_device\n",
    "r2 = pin_mem_to_device / pageable_to_device\n",
    "\n",
    "# Create a figure with the results\n",
    "fig, ax = plt.subplots()\n",
    "\n",
    "xlabels = [0, 1, 2]\n",
    "bar_labels = [\n",
    "    \"pageable_tensor.to(device) (1x)\",\n",
    "    f\"pinned_tensor.to(device) ({r1:4.2f}x)\",\n",
    "    f\"pageable_tensor.pin_memory().to(device) ({r2:4.2f}x)\"\n",
    "    f\"\\npin_memory()={100*pin_mem/pin_mem_to_device:.2f}% of runtime.\",\n",
    "]\n",
    "values = [pageable_to_device, pinned_to_device, pin_mem_to_device]\n",
    "colors = [\"tab:blue\", \"tab:red\", \"tab:orange\"]\n",
    "ax.bar(xlabels, values, label=bar_labels, color=colors)\n",
    "\n",
    "ax.set_ylabel(\"Runtime (ms)\")\n",
    "ax.set_title(\"Device casting runtime (pin-memory)\")\n",
    "ax.set_xticks([])\n",
    "ax.legend()\n",
    "\n",
    "plt.show()\n",
    "\n",
    "# Clear tensors\n",
    "del pageable_tensor, pinned_tensor\n",
    "_ = gc.collect()"
   ],
   "id": "7e52e3b3f4b10df3",
   "outputs": [
    {
     "ename": "RuntimeError",
     "evalue": "Need to provide pin_memory allocator to use pin memory.",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mRuntimeError\u001B[0m                              Traceback (most recent call last)",
      "Cell \u001B[0;32mIn[1], line 22\u001B[0m\n\u001B[1;32m     19\u001B[0m pageable_tensor \u001B[38;5;241m=\u001B[39m torch\u001B[38;5;241m.\u001B[39mrandn(\u001B[38;5;241m1_000_000\u001B[39m)\n\u001B[1;32m     21\u001B[0m \u001B[38;5;66;03m# A tensor in page-locked (pinned) memory\u001B[39;00m\n\u001B[0;32m---> 22\u001B[0m pinned_tensor \u001B[38;5;241m=\u001B[39m torch\u001B[38;5;241m.\u001B[39mrandn(\u001B[38;5;241m1_000_000\u001B[39m, pin_memory\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m)\n\u001B[1;32m     24\u001B[0m \u001B[38;5;66;03m# Runtimes:\u001B[39;00m\n\u001B[1;32m     25\u001B[0m pageable_to_device \u001B[38;5;241m=\u001B[39m timer(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mpageable_tensor.to(\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mcuda:0\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m)\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n",
      "\u001B[0;31mRuntimeError\u001B[0m: Need to provide pin_memory allocator to use pin memory."
     ]
    }
   ],
   "execution_count": 1
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
